package oraclebd;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class CriadorTabelas {
	
	ConexcaoPessoa cp;
	Statement stmt = null;
	ResultSet rs = null;
	
	public CriadorTabelas() {}
	
	public void criarTabelaQueixa(){
		
		String query;
		cp = new ConexcaoPessoa();
		Connection conexao = cp.getConnection();
		
		try {
			
			query = "CREATE TABLE tabela_queixas"+
					"(idQueixa INT, " +
					"nome VARCHAR2(30))";
			
			stmt = conexao.createStatement();
			stmt.executeUpdate(query);
			
			stmt.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void dropTabelaQueixa(){
		
		String query;
		cp = new ConexcaoPessoa();
		Connection conexao = cp.getConnection();
		
		try {
			
			query = "DROP TABLE tabela_queixas";
			
			stmt = conexao.createStatement();
			stmt.executeUpdate(query);
			
			stmt.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void inserir(){
		
		PreparedStatement pstmt = null;
		
		cp = new ConexcaoPessoa();
		Connection conexao = cp.getConnection();
		
		try {
			
			pstmt = conexao.prepareStatement("INSERT INTO tabela_queixas(idQueixa, nome) VALUES (?,?)");
			
			pstmt.setInt(1, 2);
			pstmt.setString(2, "dor");
			
			pstmt.execute();
			
			pstmt.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void select(){
		
		PreparedStatement pstmt = null;
		
		cp = new ConexcaoPessoa();
		Connection conexao = cp.getConnection();
		
		try {
			
			pstmt = conexao.prepareStatement("SELECT idqueixa, nome FROM tabela_queixas");
			
			rs = pstmt.executeQuery();
			
			while(rs.next()){
				System.out.println(rs.getString("nome"));
				System.out.println(rs.getInt("idqueixa"));
			}
			
			pstmt.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	public static void main(String[] args) {
		CriadorTabelas c = new CriadorTabelas();
//		c.inserir();
//		c.select();
//		c.dropTabelaQueixa();
	}
}
